var _contextPath;

$(document).ready(function() {
	list();
	top.UppTabs.operator = top.getCurrentTagTitle();// 设置用户tab的标题值
});

window.top["reload_rechargecard_outlist"]=function(){
	$('#rechargecard_outlist').datagrid( "load");
};

/**
 * 查询用户列表
 */
function list() {
	_contextPath = $("#contextPath").val();
	$("#rechargecard_outlist").datagrid(
			{
				queryParams : {
					cardNum : $("#cardNum").val()
							&& $("#cardNum").val() != null ? $("#cardNum")
							.val() : "",status:-99
				},
				columns : [ [{
					field : 'rechargeableCardId',
					title : '',
					hidden : true,
				}, {
					field : '_c',
					title : '',
					checkbox : true,
				}, {
					field : 'rechargeableCardNum',
					title : '卡号',
					width : 100
				},{
					field : 'opDate',
					title : '入库时间',
					width : 100,
					align : 'center',
					formatter : function(value, row, index) {
						return (new Date(Number(value))).dateConvert();
					}
				},  {
					field : 'userName',
					title : '出库人',
					width : 100
				}, {
					field : 'rechargeableCardType',
					title : '卡类型',
					width : 100,
					align : 'center',
					formatter : function(value, row, index) {
						if (value == '0') {
							return '新卡';
						} else if (value == '1') {
							return '复用卡';
						} else {
							return '新卡';
						}
					}
				}, {
					field : 'rechargeableCardStatus',
					title : '状态',
					width : 100,
					align : 'center',
					formatter : function(value, row, index) {
						if (value == '0') {
							return '入库';
						} else if (value == '1') {
							return '出库';
						} else if (value == '2') {
							return '激活';
						} else if (value == '3') {
							return '冻结';
						} else if (value == '4') {
							return '销户';
						} else {
							return '';
						}
					}
				}] ],
				autoRowHeight : true,
				fitColumns : true,
				pagination : true,
				rownumbers : true,
				checkOnSelect : true
			});
}

function getContextPath() {
	if ("" == _contextPath) {
		_contextPath = $("#contextPath").val();
	}
	return _contextPath;
}

/**
 * 搜索
 * 
 * @return
 */
function searchKey() {
	$('#rechargecard_outlist').datagrid('load', {
		cardNum : $("#cardNum").val(),status : -99
	});
}

/**
 * 新增
 */
function add(obj) {
	var backHtml = $(obj).html();
	$(obj).html('充值卡管理-新增');
	$(obj).attr('hiddenhref', getContextPath() + "iccard/rechargecard/toAddView");
	window.parent.menuClick(obj);
	$(obj).html(backHtml);
}

/**
 * 多选删除
 * 
 * @return
 */
function removeCard() {
	var rows = $("#rechargecard_outlist").datagrid("getChecked");
	if (rows.length > 0) {
		var ids = [];
		uppDialog.confirm(uppDialog.deleteMsgConfirm, function() {
			for ( var i = 0; i < rows.length; i++) {
				if(rows[i].rechargeableCardStatus=='0'){
					ids.push(rows[i].rechargeableCardId);
				}
			}
			$.ajax({
				url : getContextPath() + 'iccard/rechargecard/removeCard',
				data : {
					cardIds : ids.join(',')
				},
				type : 'POST',
				success : function(data) {
					top.uppShow(data.msgDesc);
					if ('0' == data.opResult) {
						window.location.href = getContextPath()
								+ "iccard/rechargecard/toListView";
					}
				}
			});
		});
		
	} else {
		top.uppShow(uppDialog.selectMsgUnselect);
	}
}

function removeC(rechargeableCardId) {
	uppDialog.confirm(uppDialog.deleteMsgConfirm, function() {
	$.ajax({
		url : getContextPath() + 'iccard/rechargecard/remove',
		data : {
			rechargeableCardId : rechargeableCardId
		},
		type : 'POST',
		success : function(data) {
			top.uppShow(data.msgDesc);
			if ('0' == data.opResult) {
				window.location.href = getContextPath()
						+ "iccard/rechargecard/toListView";
			}
		}
	});
});
	
	
}


